//
//  CommentTableViewCell.m
//  糗百——王桂敏
//
//  Created by 王桂敏 on 15/5/30.
//  Copyright (c) 2015年 lanouhn. All rights reserved.
//

#import "CommentTableViewCell.h"
#import "UserModel.h"
#import "UIImageView+WebCache.h"
#import "Define.h"

@interface CommentTableViewCell ()

@end

@implementation CommentTableViewCell
- (void)dealloc{
    [_contentLable release];
    [_userName release];
    [_floot release];
    [_icon release];
    [_userButton release];
    [super dealloc];
}
#pragma mark - laze loading -
- (UIImageView *)icon{
    if (!_icon) {
        self.icon = [[[UIImageView alloc] initWithFrame:CGRectMake(10, 9, 30, 30)] autorelease];
        _icon.layer.cornerRadius = 15;
        _icon.layer.masksToBounds = YES;
        _icon.userInteractionEnabled = YES;
    }
    return _icon;
}

- (UIButton *)userButton{
    if (!_userButton) {
        self.userButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _userButton.frame = CGRectMake(0, 0, 30, 30);
        _userButton.layer.cornerRadius = 15;
        _userButton.layer.masksToBounds = YES;
        [self.icon addSubview:_userButton];

    }
    return _userButton;
}



- (UILabel *)userName{
    if (!_userName) {
        self.userName = [[[UILabel alloc] initWithFrame:CGRectMake(45, 9, 200, 15)] autorelease];
        _userName.font = [UIFont systemFontOfSize:12];
        _userName.textColor = [UIColor orangeColor];
    }
    return _userName;
}
- (UILabel *)contentLable{
    if (!_contentLable) {
        self.contentLable = [[[UILabel alloc] init] autorelease];
        _contentLable.font = [UIFont systemFontOfSize:13];
        _contentLable.textColor = [UIColor grayColor];
        _contentLable.numberOfLines = 0;
        [self.contentView addSubview:_contentLable];
    }
    return _contentLable;
}
- (UILabel *)floot{
    if (!_floot) {
        self.floot = [[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth([UIScreen mainScreen].bounds) - 30, 9, 30, 15)] autorelease];
        _floot.font = [UIFont systemFontOfSize:12];
        _floot.textColor = [UIColor lightGrayColor];
        _floot.textAlignment = NSTextAlignmentCenter;
    }
    return _floot;
}
- (void)configCellWithModel:(CommentModel *)comment{
    self.contentLable.frame = CGRectMake(45, 24, kSCREENWIDTH - 55, comment.contentRect.size.height);
    self.contentLable.text = comment.content;
    self.contentLable.numberOfLines = 0;
    if (comment.user) {

        self.userName.text = comment.user.login;

    if ([comment.user.icon isKindOfClass:[NSNull class]]) {
        self.icon.image = [UIImage imageNamed:@"user_icon_anonymous"];
        } else {
        NSString *str = [NSString stringWithFormat:@"%@",comment.user.uid];
        NSURL *iconURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://pic.qiushibaike.com/system/avtnew/%@/%@/medium/%@",[str substringWithRange:NSMakeRange(0, 4)],comment.user.uid,comment.user.icon]];
        [self.icon sd_setImageWithURL:iconURL];
        }
    } else {
    self.userName.text = @"匿名人士";
    self.icon.image = [UIImage imageNamed:@"user_icon_anonymous"];
    }
    self.floot.text = [comment.floor stringValue];
}
- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.userName];
        [self.contentView addSubview:self.icon];
        [self.contentView addSubview:self.floot];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
